<!DOCTYPE html>
<html class="no-js css-menubar" lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
        <meta name="description" content="bootstrap admin template">
        <meta name="author" content="">
        <script type="text/javascript" src="../_resource/js/header.js"></script>
        <script>
            var RUN_FUNCS = [];
            var SITE_URL = "http://admin.html.me";
            var CURR_CONTROLLER = "Company";
            var CURR_ACTION = "edit";
            Breakpoints();
        </script>
        <style type="text/css">
            .list-table table td, .list-table table th{background:#fff; text-align:center;}
            .__access{display: none;}
        </style>
    </head>
    <body class="dashboard">
        <!--[if lt IE 8]>
        <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
        <![endif]-->

        <nav class="site-navbar navbar navbar-default navbar-fixed-top navbar-mega" role="navigation" id="navbardefaultmodel">
            <script type="text/javascript" src="../_resource/js/include.js" onload="HM.SomeFun('head_html')"></script>
        </nav>
        <div class="site-menubar">
            <div class="site-menubar-body" id="site-menubar-body">
                <script type="text/javascript" src="../_resource/js/include.js" onload="HM.SomeFun('nav_html')"></script>
            </div>
        </div>

        <!-- Page -->
        <div class="page">
            <div class="page-content container-fluid">
                <div class="panel form-box">
                    <div class="panel-body">
                        <form class="validate-form ajax-form" id="bossjobForm" target="_self" autocomplete="off">
                            <div class="row row-lg">
                                <div class="col-lg-6 form-horizontal">
                                    <div id="name-form-item"  class="form-group">
                                        <label for="name" class="control-label ">
                                            Name<span class="required"></span>:             
                                        </label>
                                        <div>
                                            <input type="text" name="name" id="company_name" class="form-control" disabled/>
                                        </div>
                                    </div>

                                    <div id="industry-form-item" class="form-group">
                                        <label for="industry" class="control-label ">
                                            Industry<span class="required">*</span>:             
                                        </label>
                                        <div>
                                            <select class="form-control form-control-sm" id="industry_key" name="industry_key"></select>
                                        </div>
                                    </div>

                                    <div id="city-form-item"  class="form-group">
                                        <label for="city" class="control-label ">
                                            Location<span class="required">*</span>:             
                                        </label>
                                        <div>
                                            <select class="form-control form-control-sm" id="company_location"></select>
                                        </div>
                                    </div>

                                    <div id="unit-form-item"  class="form-group">
                                        <label for="unit" class="control-label ">
                                            Unit<span class="required">*</span>:             
                                        </label>
                                        <div>
                                            <input type="text" name="unit" id="company_unit" class="form-control" />
                                        </div>
                                    </div>

                                    <div id="verify_status-form-item"  class="form-group">
                                        <label for="verify_status" class="control-label ">
                                            Verification Status:             
                                        </label>
                                        <div>
                                            <select class="form-control form-control-sm" id="verify_status" name="verify_status">
                                                <option value="1">Yes</option>
                                                <option value="0">No</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                                
                                <div class="col-lg-6 form-horizontal">
                                    <div id="company_size-form-item" class="form-group">
                                        <label for="company_size" class="control-label ">
                                            Company Size<span class="required">*</span>:             
                                        </label>
                                        <div>
                                            <select class="form-control form-control-sm" id="company_size"></select>
                                        </div>
                                    </div>

                                    <div id="website-form-item" class="form-group">
                                        <label for="website" class="control-label ">
                                            Website Address:             
                                        </label>
                                        <div>
                                            <input type="text" name="website" id="company_website" class="form-control" />
                                        </div>
                                    </div>

                                    <div id="street-form-item"  class="form-group">
                                        <label for="street" class="control-label ">
                                            Street<span class="required">*</span>:             
                                        </label>
                                        <div>
                                            <input type="text" name="street" id="company_street" class="form-control" />
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row" style="padding-bottom: 20px;">
                                <div id="logo-form-item" class="form-group">
                                    <label for="logo" class="control-label ">
                                        Company Logo:             
                                    </label>
                                    <div>
                                        <div class="dropify-photos" style="width:20%;float:left;margin:0px 10px;">
                                            <input type="file" id="input-file-now-custom-1" class="news-banner-img" data-default-file=""/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <input  type='hidden'  id='company_id' />
                                <button type="button" class="btn btn-lg btn-success" id="save-company-btn">Submit</button>
                            </div>
                        </form>
                        <div id="loading-panel" style="position: fixed;width: 300px;height: 60px;text-align: center;line-height: 60px;z-index: 10000;background-color: black;left: 50%;margin-left: -150px;top: 50%;margin-top: -30px;opacity: 0.75;color: white;display: none;">Company banner image uploading...</div>
                        <script type="text/javascript">
                            $(function(){
                                var newsBannerUrl = [];
                                //获取公司信息
                                Api.Get('getCompanyDetail', {companyId : Api.Params()['id']}, function(company_info, error){
                                    if(company_info['message'] == 'OK' && company_info['status_code'] == 200){
                                        if(company_info['data']){
                                            //公司基本信息配置
                                            Api.Get('getConfigInfo', {country_code : 'ph'}, function(object, error){
                                                if(object['message'] == 'OK' && object['status_code'] == 200){
                                                    if(object['data']){
                                                        var company_size_html = "";
                                                        $.each(object['data']['inputs']['company_sizes'],function(k,v){
                                                            var size_html = "";
                                                            for(var i in v){
                                                               size_html += "<option value='"+i+"'>"+v[i]+"</option>";
                                                            } 
                                                            company_size_html += size_html;
                                                        });
                                                        $("#company_size").html(company_size_html);
                                                        $('#company_size option[value="'+company_info['data']['company_size_key']+'"]').attr('selected', 'selected');

                                                        var company_industry_html = ""
                                                        $.each(object['data']['inputs']['industry_lists'],function(k,v){
                                                            var industry_html = "";
                                                            for(var j in v){
                                                               industry_html += "<option value='"+j+"'>"+v[j]+"</option>";
                                                            } 
                                                            company_industry_html += industry_html;
                                                        });
                                                        $("#industry_key").html(company_industry_html);
                                                        $('#industry_key option[value="'+company_info['data']['industry_key']+'"]').attr('selected', 'selected');
                                                        
                                                        var company_location_html = ""
                                                        $.each(object['data']['inputs']['region_lists'],function(k,v){
                                                            var location_html = "";
                                                            for(var p in v['locations']){
                                                               location_html += "<option value='"+v['locations'][p]['key']+"'>"+v['locations'][p]['value']+"</option>";
                                                            }
                                                            company_location_html += location_html;
                                                        });
                                                        $("#company_location").html(company_location_html);
                                                        $('#company_location option[value="'+company_info['data']['location_key']+'"]').attr('selected', 'selected');
                                                    }
                                                }else{
                                                    $.showError('Something Error, Retry Please.', 300, function(obj){
                                                        window.location.href = '/Company/index.html';
                                                    });
                                                }
                                            });
                                            $("#company_id").val(company_info['data']['id']);
                                            $("#company_name").val(company_info['data']['name']);
                                            //$("#company_location").val(company_info['data']['location']);
                                            $("#company_unit").val(company_info['data']['unit_num']);
                                            $("#company_website").val(company_info['data']['website']);
                                            $("#company_street").val(company_info['data']['street']);
                                            if(company_info['data']['is_verify']){
                                                $('#verify_status').attr('disabled', true);
                                                $('#verify_status option[value="1"]').attr('selected', 'selected');
                                            } else {
                                                $('#verify_status option[value="0"]').attr('selected', 'selected');
                                            }
                                            $('#input-file-now-custom-1').data('default-file', company_info['data']['logo']);
                                            $('.news-banner-img').dropify();
                                        }
                                    }else{
                                        $.showError('Something Error, Retry Please.', 300, function(obj){
                                            window.location.href = '/Company/index.html';
                                        });
                                    }
                                });

                                //提交数据信息
                                $("#save-company-btn").click(function(){
                                    var company_id       = $("#company_id").val(),
                                        company_location = $("#company_location").val().trim(),
                                        company_unit     = $("#company_unit").val().trim(),
                                        industry_key     = $("#industry_key :selected").val(),
                                        company_size     = $("#company_size :selected").val(),
                                        company_website  = $("#company_website").val().trim(),
                                        company_street   = $("#company_street").val().trim(),
                                        verify_status    = $("#verify_status :selected").val();
                                        
                                    if(company_id <= 0){
                                        $.showError('Something Error, Retry Please.', 300, function(){}, 2000);
                                        return false;
                                    }

                                    /*if(0 == company_website.length){
                                        $.showError('The name of the website can not be empty.', 300, function(){}, 2000);
                                        return false;
                                    }*/

                                    if(0 == company_location.length){
                                        $.showError('The name of the location can not be empty.', 300, function(){}, 2000);
                                        return false;
                                    }


                                    if(0 == company_street.length){
                                        $.showError('The name of the street can not be empty.', 300, function(){}, 2000);
                                        return false;
                                    }

                                    if(0 == company_unit.length){
                                        $.showError('The name of the unit can not be empty.', 300, function(){}, 2000);
                                        return false;
                                    }

                                    var formData     = new FormData();  
                                    var company_logo = $('#input-file-now-custom-1')[0].files[0];
                                    if(company_logo){
                                        formData.append('logo', company_logo);
                                        $('#loading-panel').show();
                                        $.ajax({
                                            data       : formData,  
                                            type       : "POST",  
                                            url        : API_HOSTNAMES['data_api']+'/api/v1/companies/'+company_id+'/logo',  
                                            cache      : false,  
                                            contentType: false,  
                                            processData: false,  
                                            success: function(rtn) {
                                                $('#loading-panel').hide();
                                            }  
                                       }); 
                                    }
                                    
                                    //Save Company Info
                                    var companyData = {
                                        coordinator_id      : Api.Params()['id'],
                                        industry_key      : industry_key,
                                        country_key       : 'ph',
                                        location_key      : company_location,
                                        website           : company_website,
                                        company_size_key  : company_size,
                                        unit_num          : company_unit,
                                        street            : company_street
                                    };
                                    $('#loading-panel').html('Saving Company Data...');
                                    $('#loading-panel').show();
                                    Api.Put('updateCompnay' , companyData , function(object, error){
                                        $('#loading-panel').hide();
                                        if(object['message'] && object['status_code'] && object['message'] == 'OK' && object['status_code'] == 200){
                                            if(verify_status > 0 && $("#verify_status").attr("disabled") != 'disabled'){
                                                var post_url = API_HOSTNAMES['data_api']+'/api/v1/companies/'+company_id+'/change_verification_status';
                                                $.ajax({ 
                                                    url : post_url,
                                                    type: 'PATCH',
                                                    data: { is_verify : 1 }
                                                });
                                            }
                                            $.showSuccess('Save Company Successfully.', 300, function(){
                                                window.location.href = '/Company/index.html';
                                            });
                                        }else{
                                            $.showError('Something Error, Retry Please.', 300, function(){});
                                        }
                                    });
                                });
                            });
                        </script>
                    </div>
                </div>
            </div>

            <!-- Modal -->
            <div class="modal fade" id="confirmModal" aria-hidden="true" role="dialog" tabindex="-1">
                <div class="modal-dialog modal-center">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 class="modal-title"></h4>
                        </div>
                        <div class="modal-body">
                            <p></p>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                            <button type="button" class="btn btn-primary"></button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal fade" id="alertModal" aria-hidden="true" role="dialog" tabindex="-1">
                <div class="modal-dialog modal-center">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">×</span>
                            </button>
                            <h4 class="modal-title"></h4>
                        </div>
                        <div class="modal-body">
                            <p></p>
                        </div>
                    </div>
                </div>
            </div>
            <!-- End Modal -->
        </div>
        <!-- End Page -->

        <!-- Footer -->
        <script type="text/javascript" src="../_resource/js/footer.js"></script>
        <script>
            (function (document, window, $) {
                'use strict';

                var Site = window.Site;
                $(document).ready(function () {
                    Site.run();
                    $('textarea[maxlength]').maxlength({
                        threshold: 1000,
                        placement: 'bottom-left-inside'
                    });

                    $.components.register("datepicker", {mode: "default", defaults: {autoclose: !0}});

                    if (RUN_FUNCS.length > 0) {
                        for (var i = 0; i < RUN_FUNCS.length; i++) {
                            RUN_FUNCS[i].call();
                        }
                    }
                });
            })(document, window, jQuery);
        </script>
    </body>
</html>